//
//  AccountHeadView.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/11/2.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import UIKit

class AccountHeadView: UIView {

    let redView = UIView()
    let titleLabel = UILabel()
    
    fileprivate let whiteView = UIView()
    fileprivate let amountTipLabel = UILabel()
    fileprivate let amountLabel = UILabel() //总余额
    fileprivate let cardNumberLabel = UILabel() //卡号
    fileprivate let addBillLabel = UILabel() //添加账单
    fileprivate let recordLabel = UILabel() //记录账单
    fileprivate let multipleBillLabel = UILabel() //多种账单
    fileprivate let quickLabel = UILabel() //快速还款
    
    fileprivate let recordImage = UIImageView()
    fileprivate let multipleBillImage = UIImageView()
    fileprivate let quickImage = UIImageView()
    
    override init(frame: CGRect) {
      super.init(frame: frame)
        
        self.backgroundColor = UIColor.mineColor()
        
        redView.backgroundColor = UIColor.red
        self.addSubview(redView)
        
        titleLabel.text = "HI, " + getCurrentTime()
        titleLabel.font = UIFont.boldSystemFont(ofSize: RATIO(maxNum: 25))
        titleLabel.textColor = UIColor.white
        titleLabel.textAlignment = .center
        redView.addSubview(titleLabel)
        
        whiteView.backgroundColor = UIColor.white
        whiteView.layer.cornerRadius = 10
        whiteView.layer.masksToBounds = true
        self.addSubview(whiteView)
        
        amountTipLabel.text = totalBalance + ":"
        amountTipLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 18))
        whiteView.addSubview(amountTipLabel)
        
        amountLabel.text = "¥0.00"
        amountLabel.textColor = UIColor.red
        amountLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 18))
        whiteView.addSubview(amountLabel)
        
        cardNumberLabel.text = "* * * *  * * * *  * * * *  * * * *"
        cardNumberLabel.textAlignment = .center
        cardNumberLabel.textColor = UIColor.gray
        cardNumberLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 20))
        whiteView.addSubview(cardNumberLabel)
        
        addBillLabel.text = updateBill
        addBillLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
        addBillLabel.textAlignment = .center
        whiteView.addSubview(addBillLabel)
        
        recordLabel.text = recordBills
        recordLabel.textColor = UIColor.gray
        recordLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
        whiteView.addSubview(recordLabel)
        
        multipleBillLabel.text = multipleBills
        multipleBillLabel.textColor = UIColor.gray
        multipleBillLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
        whiteView.addSubview(multipleBillLabel)
        
        quickLabel.text = quickRepayment
        quickLabel.textColor = UIColor.gray
        quickLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
        whiteView.addSubview(quickLabel)
        
        recordImage.image = #imageLiteral(resourceName: "select_red")
        whiteView.addSubview(recordImage)
        
        multipleBillImage.image = #imageLiteral(resourceName: "select_green")
        whiteView.addSubview(multipleBillImage)
        
        quickImage.image = #imageLiteral(resourceName: "select_yellow")
        whiteView.addSubview(quickImage)
        
        redView.snp.makeConstraints { (make) in
            make.top.left.right.equalToSuperview()
            make.height.equalTo(RATIO_H(maxNum: 200))
        }
        
        titleLabel.snp.makeConstraints { (make) in
            make.left.right.equalToSuperview()
            make.centerY.equalToSuperview().offset(RATIO_H(maxNum: -20))
            make.height.equalTo(RATIO_H(maxNum: 30))
        }
        
        whiteView.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(RATIO(maxNum: 20))
            make.right.equalToSuperview().offset(RATIO(maxNum: -20))
            make.top.equalTo(redView.snp.bottom).offset(RATIO_H(maxNum: -40))
            make.height.equalTo(RATIO_H(maxNum: 180))
        }
        
        amountTipLabel.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(RATIO_H(maxNum: 25))
            make.left.equalToSuperview().offset(RATIO(maxNum: 20))
            make.height.equalTo(RATIO_H(maxNum: 30))
            make.width.greaterThanOrEqualTo(10)
        }
        
        amountLabel.snp.makeConstraints { (make) in
            make.centerY.equalTo(amountTipLabel)
            make.right.equalToSuperview().offset(RATIO(maxNum: -20))
            make.height.equalTo(amountTipLabel)
            make.width.greaterThanOrEqualTo(10)
        }
        
        cardNumberLabel.snp.makeConstraints { (make) in
            make.top.equalTo(amountTipLabel.snp.bottom).offset(RATIO_H(maxNum: 20))
            make.left.right.equalToSuperview()
            make.height.equalTo(RATIO_H(maxNum: 20))
        }
        
        addBillLabel.snp.makeConstraints { (make) in
            make.top.equalTo(cardNumberLabel.snp.bottom).offset(RATIO_H(maxNum: 10))
            make.left.right.equalToSuperview()
            make.height.equalTo(RATIO_H(maxNum: 20))
        }
        
        multipleBillLabel.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview().offset(RATIO(maxNum: 12))
            make.top.equalTo(addBillLabel.snp.bottom).offset(RATIO_H(maxNum: 20))
            make.height.equalTo(RATIO_H(maxNum: 20))
            make.width.greaterThanOrEqualTo(10)
        }
        
        multipleBillImage.snp.makeConstraints { (make) in
            make.right.equalTo(multipleBillLabel.snp.left).offset(RATIO(maxNum: -2))
            make.centerY.equalTo(multipleBillLabel)
            make.width.height.equalTo(RATIO_H(maxNum: 20))
        }
        
        recordImage.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(RATIO(maxNum: 20))
            make.centerY.equalTo(multipleBillLabel)
            make.width.height.equalTo(RATIO_H(maxNum: 20))
        }
        
        recordLabel.snp.makeConstraints { (make) in
            make.centerY.equalTo(multipleBillLabel)
            make.left.equalTo(recordImage.snp.right).offset(RATIO(maxNum: 2))
            make.width.greaterThanOrEqualTo(10)
            make.height.equalTo(multipleBillLabel)
        }
        
        quickLabel.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(RATIO(maxNum: -20))
            make.centerY.equalTo(recordLabel)
            make.width.greaterThanOrEqualTo(10)
            make.height.equalTo(recordLabel)
        }
        
        quickImage.snp.makeConstraints { (make) in
            make.right.equalTo(quickLabel.snp.left).offset(RATIO(maxNum: -2))
            make.centerY.equalTo(quickLabel)
            make.width.height.equalTo(RATIO_H(maxNum: 20))
        }
        
        
        
    }
    
    //MARK: 获取当前时间
    func getCurrentTime() -> String {
        
        let date = Date()
        let calendar = Calendar.init(identifier: .gregorian)
        var comps = calendar.dateComponents([.year,.month,.day,.weekday,.hour,.minute,.second], from: date)
        let time = comps.hour!
        
        var text = ""
        
        if time >= 1 && time < 5 {
            text = "凌晨好"
        }else if time >= 5 && time < 8 {
            text = "早上好"
        }else if time >= 8 && time < 11 {
            text = "上午好"
        }else if time >= 11 && time < 13 {
            text = "中午好"
        }else if time >= 13 && time < 17 {
            text = "下午好"
        }else if time >= 17 && time < 19 {
            text = "傍晚好"
        }else if time >= 19 && time < 23 {
            text = "晚上好"
        }else {
            text = "深夜好"
        }
        
        return text
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
